#include <iostream>
#include <vector>
#include <climits>

using namespace std;

// 1423. 可获得的最大点数
// https://leetcode.cn/problems/maximum-points-you-can-obtain-from-cards/description/

class Solution
{
public:
    int maxScore(vector<int> &cardPoints, int k)
    {
        int ret = INT_MAX;
        int left = 0;
        int n = cardPoints.size();
        int sum = 0;
        int windowsSum = 0;
        int windowsLen = n - k;
        for (int i = 0; i < n; i++)
        {
            sum += cardPoints[i];
            windowsSum += cardPoints[i];

            if(i - left + 1 < windowsLen){
                continue;
            }

            ret = min(ret, windowsSum);
            windowsSum -= cardPoints[left++];
        }
        return windowsLen == 0? sum: sum - ret;
    }
};

int main()
{
    return 0;
}